﻿@{
    ViewBag.Title = "文章列表";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
    int no = 1;
    string pageindex = "1";
    if (!string.IsNullOrEmpty(Request["PageIndex"]))
    {
        pageindex = Request["PageIndex"].ToString();
    }
    
}
@using Utils = UcAsp.Net.Comm.Utils;
@model List<UcAsp.Net.Model.ArticelsViews>
    <div class="container-fluid">
        <div class="span2">
            <input type="text" id="searchTitle" placeholder="标题搜索" />
        </div>
        <div class="span2">
            <span class="btn" id="btnSearch"><i class="icon-search"></i></span>
        </div>
        <div class="span11">
            <div id="breadcrumb">
                
            </div>
        </div>
        <div class="row-fluid">
            <div class="widget-box">
                <div class="widget-title">
                    <span class="icon"><i class="icon-th"></i></span>
                    <h5>
                        类目管理
                    </h5>
                </div>
                <div class="widget-content nopadding">
                    <table class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th>
                                    序号
                                </th>
                                <th>
                                    类目
                                </th>
                                <th>
                                    标题
                                </th>
                                <th>
                                    图片
                                </th>
                                <th>
                                    是否推荐
                                </th>
                                <th>
                                    添加时间
                                </th>
                                <th>
                                    操作
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (UcAsp.Net.Model.ArticelsViews v in Model)
                            {
                                <tr style="height:120px;">
                                    <td>
                                        @no
                                    </td>
                                    <td>
                                        <a href="/admin/Articles?CID=@v.CategorieID"> @v.CategorieName</a>
                                    </td>
                                <td>
                                    @v.Title
                                </td>
                                    <td>
                                        @if (!string.IsNullOrEmpty(v.IconUrl))
                                        {
                                            <img class="img-rounded showpic" src="@v.IconUrl" style="max-width:70px; max-height:70px; cursor:pointer" />
                                        }
                                    </td>
                                <td>
                                    @Utils.GetCode(v.IsRecommend, new object[] { true, "是", false, "否" })
                                </td>
                                <td>
                                    @v.AddDatetime.ToString("yyyy-MM-dd")
                                </td>
                                <td><div class="btn-group">
                                    <a class="btn" href="/Admin/ArticlesPageManager?ID=@v.ID&CID=@v.CategorieID">分页列表</a>
                                    <a class="btn" href="/Admin/ArticlesManager?ID=@v.ID&CID=@v.CategorieID">编辑</a>
                                    <span class="btn recommand" data-id="@v.ID">
                                        <i class="@Utils.GetCode(v.IsRecommend, new object[] { true, "icon-thumbs-up", false, "icon-thumbs-down" })"></i>
                                        @Utils.GetCode(v.IsRecommend, new object[] { true, "取消", false, "推荐" })
                                    </span>
                                    <span class="btn release" data-id="@v.ID">
                                        <i class="@Utils.GetCode(v.IsRecommend, new object[] { true, "icon-thumbs-up", false, "icon-thumbs-down" })"></i>
                                        @Utils.GetCode(v.IsRecommend, new object[] { true, "下架", false, "上架" })
                                    </span>

                                    <span class="btn delete" data-id="@v.ID">删除</span>
                                </div>      
                            </td>
                                                                                                                                                                                                                                                                                                                    </tr>
                                                                                                                                                                                                                                                                                                                                  no++;
                            }
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="7">
                                    <div class="btn-group">
                                        <a class="btn" href="/admin/articles?PageIndex=1&@ViewData["CID"]@ViewData["UserID"]">
                                            <i class="icon-step-backward"></i>
                                        </a><a class="btn" href="/admin/articles?PageIndex=@ViewData["Pre"]@ViewData["CID"]@ViewData["UserID"]">
                                            <i class="icon-backward"></i>
                                        </a>
                                        @if (int.Parse(ViewData["PageCount"].ToString()) < 20)
                                        {
                                            for (int i = 1; i < int.Parse(ViewData["PageCount"].ToString()) + 1; i++)
                                            {
                                                if (i.ToString() != pageindex)
                                                {
                                                    <a class="btn" href="/admin/articles?PageIndex=@i@ViewData["CID"]@ViewData["UserID"]">
                                                        @i.ToString()
                                                    </a>
                                                }
                                                else
                                                {
                                                    <a class="btn btn-link" href="/admin/articles?PageIndex=@i@ViewData["CID"]@ViewData["UserID"]">
                                                        @i.ToString()
                                                    </a>
                                                }

                                            }
                                        }
                                        else
                                        {
                                            int pagecount = (int.Parse(ViewData["Next"].ToString()) + 10) > int.Parse(ViewData["PageCount"].ToString()) ? int.Parse(ViewData["PageCount"].ToString()) : (int.Parse(ViewData["Next"].ToString()) + 10);
                                            for (int i = (int.Parse(ViewData["Pre"].ToString()) - 5) > 0 ? (int.Parse(ViewData["Pre"].ToString()) - 5) : 1; i < pagecount; i++)
                                            {
                                                if (i.ToString() != pageindex)
                                                {
                                                    <a class="btn" href="/admin/articles?PageIndex=@i@ViewData["CID"]@ViewData["UserID"]">
                                                        @i.ToString()
                                                    </a>
                                                }
                                                else
                                                {
                                                    <a class="btn btn-link" href="/admin/articles?PageIndex=@i@ViewData["CID"]@ViewData["UserID"]">
                                                        @i.ToString()
                                                    </a>
                                                }
                                            }

                                        }
                                        <a class="btn" href="/admin/articles?PageIndex=@ViewData["Next"]@ViewData["CID"]@ViewData["UserID"]">
                                            <i class="icon-forward"></i>
                                        </a><a class="btn" href="/admin/articles?PageIndex=@ViewData["PageCount"]@ViewData["CID"]@ViewData["UserID"]">
                                            <i class="icon-step-forward"></i>
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(document).ready(function () {
            $(".recommand").click(function () {
                $.post("/Admin/ArticlesRecommad", { ID: $(this).attr("data-id") }, function (dataresult) {
                    location.reload();
                })
            });
            $(".release").click(function () {
                $.post("/Admin/ArticlesRelease", { ID: $(this).attr("data-id") }, function (dataresult) {
                    location.reload();
                })
            });
            $(".delete").click(function () {
                $.post("/Admin/ArticlesDel", { ID: $(this).attr("data-id") }, function (dataresult) {
                    location.reload();
                })
            });
            $("#btnSearch").click(function () {
                location.href = "/Admin/Articles/?keyword=" + $("#searchTitle").val();
            });
            $(".showpic").click(function () {
                $.facebox("<img src="+$(this).attr("src")+">", "ImagePic");

            })
        })

    </script>
